layui.define(['table', 'form'], function(exports){
  var $ = layui.$,table = layui.table,form = layui.form;

  var tradeNo = $('input[name="tradeNo"]').val();
  var createDate = $('input[name="createDate"]').val();

  table.render({
    elem: '#LAY-table'
    ,url: layui.setter.webRoot + '/member/order/user/list.data'
      ,where:{tradeNo:tradeNo,createDate:createDate}
    ,method: 'post'
    ,parseData: function (res) {
        return {
            "code": res.code,
            "msg": res.msg,
            "count": res.body.total,
            "data": res.body.data
        };
    }
    ,response: {statusCode: 200}
    ,cols: [[
      {field: 'userId',title: '用户ID'}
      ,{field: 'userName',title: '用户昵称',templet:function (record){
              return record.user.name;
        }}
      ,{field: 'userPhone',title: '用户手机号',templet:function (record){
              return record.user.phone;
          }}
      ,{field: 'roleNames', title: '角色'}
    ]]
    ,page: false
    ,height: 'full'
    ,text: '对不起，加载出现异常！'
  });

    //事件
    var active = {
        refreshOrderUser:function (){
            layer.confirm('确定要刷新订单关联用户吗？', function(index){
                $.ajax({
                    type: "post",
                    url: layui.setter.webRoot + '/member/order/user/refresh.do',
                    data:{tradeNo:tradeNo,createDate:createDate},
                    dataType:"json",
                    success:function(res){
                        if(res.code == 200){
                           layer.msg('刷新成功',{icon:1});
                           table.reload('LAY-table');
                        }else{
                            layer.msg(res.msg,{icon: 5});
                        }
                    }
                });
                layer.close(index);
            });
        }
    };

    $('.layui-btn.LAY-btn-fun').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
  
  table.on('tool(LAY-table)', function(obj){
  	var type = obj.event ;
   	active[type] ? active[type].call(this,obj) : '';
  });
  
  exports('member_order_business_info', {})
});